package com.tiendung.basicviewdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.Toast;

public class SignupActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_signup);

		ImageButton btnOK = (ImageButton) findViewById(R.id.btnOK);
		btnOK.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				submit(v);
			}
		});
	}

	private void submit(View v) {
		EditText txtUsername = (EditText) findViewById(R.id.txtUsername);
		String username = txtUsername.getText().toString();
		EditText txtPassword = (EditText) findViewById(R.id.txtPassword);
		String password = txtPassword.getText().toString();
		EditText txtPassword2 = (EditText) findViewById(R.id.txtPassword2);
		String password2 = txtPassword2.getText().toString();
		if (!password.equals(password2)) {
			Toast.makeText(getBaseContext(), "Confirm password not match!",
					Toast.LENGTH_LONG).show();
			txtPassword.setText("");
			txtPassword2.setText("");
			txtPassword.requestFocus();
			return;
		}

		EditText txtEmail = (EditText) findViewById(R.id.txtEmail);
		String email = txtEmail.getText().toString();
		RadioButton rbMale = (RadioButton) findViewById(R.id.rbMale);
		String sexual = "Male";
		if (rbMale.isChecked() == false) {
			sexual = "Female";
		}

		String userInformation = "Username: " + username + "\nPassword:"
				+ password + "\nEmail:" + email + "\nSexual: " + sexual;
		Toast.makeText(getBaseContext(), userInformation, Toast.LENGTH_LONG)
				.show();
	}

}
